package com.ms.log.context;

import com.ms.log.appender.Appender;
import com.ms.log.logger.Logger;

import java.util.HashMap;
import java.util.Map;

/**
 * @author zdh
 * 用于管理 很多个日志记录者 logger, 这些logger 可能用于记录不同的包路径下的日志
 */
public class LoggerContext {

    public LoggerContext(Logger root){
        this.root = root;
    }
    private Logger root;

    public Logger getRoot() {
        return root;
    }

    public void setRoot(Logger root) {
        this.root = root;
    }

    /**
     * logger缓存，存放解析配置文件后生成的logger对象，以及通过程序手动创建的logger对象
     */
    private Map<String,Logger> loggerCache = new HashMap<>();

    /**
     * Appender缓存，存放解析配置文件后生成的Appender对象
     */
    private Map<String, Appender> appenderCache = new HashMap<>();

    public void addLogger(String name,Logger logger){
        loggerCache.put(name,logger);
    }

    public Logger getLogger(String name){
        return loggerCache.get(name);
    }


    public void addAppender(String name,Appender appender){
        appenderCache.put(name,appender);
    }

    public Appender getAppender(String name){
        return appenderCache.get(name);
    }

    public Map<String, Logger> getLoggerCache() {
        return loggerCache;
    }

    public void setLoggerCache(Map<String, Logger> loggerCache) {
        this.loggerCache = loggerCache;
    }

    public Map<String, Appender> getAppenderCache() {
        return appenderCache;
    }

    public void setAppenderCache(Map<String, Appender> appenderCache) {
        this.appenderCache = appenderCache;
    }
}
